﻿using System;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Tisonet.Dobrak.Client.WP8.ViewModels;

namespace Tisonet.Dobrak.Client.WP8.Views
{
    public partial class ProjectionsView : PhoneApplicationPage
    {
        // Constructor
        public ProjectionsView()
        {
            InitializeComponent();

            DataContext = App.ViewModel;

            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();
        }

        // Sample code for building a localized ApplicationBar
        //private void BuildLocalizedApplicationBar()
        //{
        //    // Set the page's ApplicationBar to a new instance of ApplicationBar.
        //    ApplicationBar = new ApplicationBar();

        //    // Create a new button and set the text value to the localized string from AppResources.
        //    ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
        //    appBarButton.Text = AppResources.AppBarButtonText;
        //    ApplicationBar.Buttons.Add(appBarButton);

        //    // Create a new menu item with the localized string from AppResources.
        //    ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
        //    ApplicationBar.MenuItems.Add(appBarMenuItem);
        //}

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (!App.ViewModel.IsDataLoaded)
            {
                App.ViewModel.LoadData();
            }

        }

      

        private void ListProjections_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (ListProjections.SelectedItem == null)
            {
                return; 
            }

            var selectedProjection = ListProjections.SelectedItem as ProjectionViewModel;

            if (selectedProjection != null)
            {
                NavigationService.Navigate(new Uri("/Views/MovieDetailView.xaml?ID=" + selectedProjection.ID, UriKind.Relative));
            }

        
        }
    }

    
}